//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System;

namespace OpenLS.Chart.UI
{
    internal class BarStack: ChartStack
    {
        private readonly Dictionary<int, BarStackItem> allItems = new Dictionary<int, BarStackItem>();
        private readonly List<BarStackItem> negaviteItems = new List<BarStackItem>();
        private readonly List<BarStackItem> positiveItems = new List<BarStackItem>();

        public override double Minimum
        {
            get
            {
                if (negaviteItems.Count == 0)
                    return 0;
                return negaviteItems[negaviteItems.Count - 1].bounds.Low;
            }
        }

        public override double Maximum
        {
            get
            {
                if (positiveItems.Count == 0)
                    return 0;
                return positiveItems[positiveItems.Count - 1].bounds.High;
            }
        }

        public override void AddValue(NumericValue value, int seriesIndex)
        {
            if (value.Value >= 0)
            {
                var i = new BarStackItem(Maximum, value);
                allItems.Add(seriesIndex, i);
                positiveItems.Add(i);
            }
            else
            {
                var i = new BarStackItem(Minimum, value);
                allItems.Add(seriesIndex, i);
                negaviteItems.Add(i);
            }
        }

        public override Bounds GetBounds(int seriesIndex)
        {
            return allItems[seriesIndex].bounds;
        }
        public override double GetValue(int seriesIndex)
        {
            throw new NotSupportedException();
        }
    }
}
